package com.example.abc.exception;

import org.springframework.http.HttpStatus;

/**
 * Created by Peter on 2018/4/26.
 */
public class ServerException extends RuntimeException {
    private int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
    private Long timestamp = System.currentTimeMillis();
    private String message;// 给用户看到友好的消息，提示用户错误原因，或者碰到这个错误该如何操作
    private String errorDetail;// 给开发看的错误详情，用于定位错误原因。

    public String toJson(){
        return "{\"status\":"+status+", \"timestamp\":"+timestamp+", \"message\":\""+message+"\", \"errorDetail\":\""+errorDetail+"\"}";
    }
    public ServerException() {
    }

    public ServerException(String message) {
        super(message);
        this.message = message;
    }

    public ServerException(String message, String errorDetail) {
        super(message);
        this.message = message;
        this.errorDetail = errorDetail;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getErrorDetail() {
        return errorDetail;
    }

    public void setErrorDetail(String errorDetail) {
        this.errorDetail = errorDetail;
    }
}
